<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 老猫 <zxxjjforever@163.com>
// +----------------------------------------------------------------------

// [ 模拟post提交 ]
/*print_r(number_format(hexdec('799980000000000000000000000')) * pow(10,-$currency_row['precision']));die;
print_r(printf('%2f',hexdec('0x5af3107a4000')));die;*/

//$url = http://biboapi.com/api/index
//http://192.168.10.120:5020
//http://bibo.camwallet.cn
//http://walletapi.cm
//http://110.88.129.59:8081
//http://app.api.bibowallet.com
//$url = 'http://walletapi.cm/exchange/currency/userCurrencyList';
//$url = 'http://walletapi.cm/wallet/localWallet/apiSearchBalance';
//testnet.bibo.camwallet.cn:8081
//mainnet.bibo.camwallet.cn:8081

//设备 (查询数据库)
$app_id = 'bibo';
$db = new MySQLi('192.168.10.113','bibodb','zqtb#123','bibodb2','3306');
$sql='select * from bi_apps where app_id ="'.$app_id.'"';
$res = $db->query($sql);
$row = $res->fetch_all();
//数据
/* ------------------------------------   设置参数  ------------------------------------------------------*/
$app_secret = $row['0']['secret'];
//控制器
$method = 'currency';
//方法
$action = 'currencyList';
//随机签名
$nonce = 'wdjrtrgjcodewmgblwsger';
$sign_method = 'md5';     // (md5 必须加密)
//基础参数
$base = array('app_id'=> $app_id,'method'=> $method,'action'=> $action,'format'=> 'json','sign_method'=> $sign_method,'nonce'=> $nonce);
//业务参数
$request = array('wallet_type'=> 'cam','address'=> 'AQ6DTbecNaD1JZdxQLfj4KM8QgHcmyRJv7');

/* ------------------------------------   设置参数  ------------------------------------------------------*/
//签名
$param = array_merge($base,$request);
ksort($param);
$tmps = array();
foreach ( $param as $k => $v ) {
    $tmps[] = $k . $v;
}
$sign = $app_secret . implode('', $tmps) . $app_secret;
if($sign_method != 'md5'){
    $param['sign'] = $sign;
}else{
    $param['sign'] = true;
}

//$param['sign'] = $sign;

/*$param_str = '{"name":"123456","password":"123456","code":"0001","app_id":"'.$app_id.'","method":"demo","action":"","format":"json","sign_method":"md5","nonce":"1234"}';*/


$url = 'http://biboapi.cm/api/index';
//$param = json_decode($param_str,true);
function curl_post($url, $post){
$options = array(
    CURLOPT_RETURNTRANSFER =>true,
    CURLOPT_HEADER =>false,
    CURLOPT_HTTPHEADER=> ['XX-Token:6926949a3f8bf994bcd07b5ce18c36e7928b697f069313b80299f0dba2bceb7c','XX-Device-Type:iphone','XX-Node-Url:http://192.168.10.120:8000'],
    CURLOPT_POST  => true,
    CURLOPT_POSTFIELDS => http_build_query($post),
    CURLOPT_POST  => true,
    CURLOPT_POSTFIELDS => $post,
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$data = curl_post($url,$param);
print_r($data);
